package db.util;


public class Column {
	private boolean nullable;
	private String name;
	private String dataType;
	private int size;
	private Integer decDigits;
	public boolean isNullable() {
		return nullable;
	}
	public String getName() {
		return name;
	}
	public String getDataType() {
		return dataType;
	}
	public int getSize() {
		return size;
	}
	public Column(String name, String dataType, int size, boolean nullable, Integer decDigits) {
		this.name = name.toLowerCase();
		this.dataType = dataType;
		this.size = size;
		this.nullable = nullable;
		this.decDigits = decDigits;
	}
	@Override
	public String toString() {
		return String.format("%s (%s,%s%s%s)", name, dataType, size, decDigits != 0 ? "," + decDigits : "", nullable ? ",N":"");
	}
	public boolean equals(Column b, StringTree report) {
		boolean result = name.equals(b.name) && nullable == b.nullable && dataType.equals(b.dataType) && size == b.size;
		if (!result) {
			report.printf(" Columns differ: A:%s B:%s%n", this, b);
		}
		return result;
	}
	public boolean equalsIgnoreDataType(Column b, StringTree report) {
		boolean result = name.equals(b.name) && nullable == b.nullable && size == b.size;
		if (!result) {
			report.printf(" Columns differ: A:%s B:%s%n", this, b);
		}
		return result;
	}
}
